using System;
using System.Collections.Generic;
using System.Text;
using AllegNet;

namespace DemonHunter
{
    class Grenade:Entity
    {
        //data
        private static Bmp bitmap;
        private bool timerStarted = false;
        private DateTime start;

        //constructor
        public Grenade()
        {
            entityYLoc = PlayerCharacter.GetInstance().getEntityYLoc() + 75;
            entityXLoc = PlayerCharacter.GetInstance().getEntityXLoc() + 100;
        }
        //overridden functions
        public override void move() 
        {
            moveDown();

            // start timer if this is the first time this method has been called
            if (timerStarted == false)
            {
                timerStarted = true;
                start = DateTime.Now;
            }

            // explode grenade if 0.3 seconds have elapsed
            DateTime stop = DateTime.Now;
            TimeSpan elapsed = stop - start;
            if (elapsed.Milliseconds > 300)
            {
                Sound.playSound(Sound.SOUND_EXPLODE);
                Explosion explode = new Explosion();
                explode.setEntityXLocation(entityXLoc - 100);
                explode.setEntityYLocation(entityYLoc - explode.GetCurrentBitmapHeight() + 50);
                Logic.GetInstance().DetectExplosionCollisions(explode);
                Level.GetInstance().AddEntity(explode);
                Level.GetInstance().RemoveEntity(this);
            }
        }

        /// <summary>
        /// not necessary
        /// </summary>
        public override void animate()
        {

        }

        public override Bmp GetCurrentBitmap()
        {
            return bitmap;
        }
        /// <summary>
        /// load bitmaps into memory
        /// </summary>
        public new static void LoadBitmaps()
        {
            bitmap = Game.GetInstance().LoadBitmap("C:\\DemonHunterart\\grenade.bmp");
        }
        /// <summary>
        /// return current bitmap height
        /// </summary>
        /// <returns></returns>
        public override double GetCurrentBitmapHeight()
        {
            return bitmap.Height;
        }
    }
}
